package com.ruoyi.web.controller.user;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.user.VsDramasUserBank;
import com.ruoyi.system.service.user.IVsDramasUserBankService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
/**
 * 提现银行卡Controller
 * 
 * @author zzx
 * @date 2024-04-30
 */
@Api(tags = "提现银行卡")
@RestController
@RequestMapping("/user/bank")
public class VsDramasUserBankController extends BaseController
{
    @Autowired
    private IVsDramasUserBankService vsDramasUserBankService;

    /**
     * 查询提现银行卡列表
     */
    @ApiOperation("查询提现银行卡列表")
    @GetMapping("/list")
    public TableDataInfo list(VsDramasUserBank vsDramasUserBank)
    {
        if (getLoginUser().getVsUser() == null) {
            TableDataInfo tableDataInfo = new TableDataInfo();
            tableDataInfo.setCode(500);
            tableDataInfo.setMsg("暂未登录！");
            return tableDataInfo;
        }
        if (getLoginUser().getVsUser().getId() != null) {
            vsDramasUserBank.setUserId(getLoginUser().getVsUser().getId());
        }
        startPage();
        List<VsDramasUserBank> list = vsDramasUserBankService.selectVsDramasUserBankList(vsDramasUserBank);
        return getDataTable(list);
    }

    /**
     * 导出提现银行卡列表
     */
//    @ApiOperation("导出提现银行卡列表")
    @Log(title = "提现银行卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VsDramasUserBank vsDramasUserBank)
    {
        List<VsDramasUserBank> list = vsDramasUserBankService.selectVsDramasUserBankList(vsDramasUserBank);
        ExcelUtil<VsDramasUserBank> util = new ExcelUtil<VsDramasUserBank>(VsDramasUserBank.class);
        util.exportExcel(response, list, "提现银行卡数据");
    }

    /**
     * 获取提现银行卡详细信息
     */
//    @ApiOperation("获取提现银行卡详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vsDramasUserBankService.selectVsDramasUserBankById(id));
    }

    /**
     * 新增提现银行卡
     */
    @ApiOperation("新增提现银行卡")
    @Log(title = "提现银行卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VsDramasUserBank vsDramasUserBank)
    {
        if (getLoginUser().getVsUser() == null) {
            return error("暂未登录！");
        }
        vsDramasUserBank.setUserId(getLoginUser().getVsUser().getId());
        return toAjax(vsDramasUserBankService.insertVsDramasUserBank(vsDramasUserBank));
    }

    /**
     * 修改提现银行卡
     */
//    @ApiOperation("修改提现银行卡")
    @Log(title = "提现银行卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VsDramasUserBank vsDramasUserBank)
    {
        return toAjax(vsDramasUserBankService.updateVsDramasUserBank(vsDramasUserBank));
    }

    /**
     * 删除提现银行卡
     */
//    @ApiOperation("删除提现银行卡")
    @Log(title = "提现银行卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vsDramasUserBankService.deleteVsDramasUserBankByIds(ids));
    }

    @PostMapping(value = "/getAccountInfo")
    public AjaxResult getAccountInfo(@RequestBody VsDramasUserBank vsDramasUserBank)
    {
        if (getLoginUser().getVsUser() == null) {
            return error("暂未登录！");
        }
        vsDramasUserBank.setUserId(getLoginUser().getVsUser().getId());
        VsDramasUserBank userBank = vsDramasUserBankService.selectUserBankByParams(vsDramasUserBank);
        if (userBank == null) {
            return success(new VsDramasUserBank());
        }
        return success(userBank);
    }

}
